<?php
    $url = new Url(); 
    $forder_upload = "ringBack";  
    $link_avatar = Yii::app()->params["urlImages"] . "upload_avatar_category_ring.php?forder_upload=" . $forder_upload;     
?>
<link rel="stylesheet" href="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/css/swfupload.css" type="text/css" />
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/handlers.js"></script>
<script type="text/javascript">
window.onload = function() {
        var configUploadData = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:'<?php echo $data["create_date"];?>',
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_avatar;?>", 
            file_types: "*.jpg;*.jpeg;*.png;*.gif", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }
        configUpload(configUploadData);    
    }; 
    
     function uploadResponse(serverData){  
        try {
            $("#txtFileName").val(""); 
            var response = $.parseJSON(serverData); 
            if(response.code==404){
                alert(response.message);return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;
            $("#picture").val(filename);
            $("#show_pic").html('<img src="<?php echo Yii::app()->params["urlImages"].$forder_upload.'/';?>'+path +'/'+ filename +'">')
        } catch (e) {

        };
    }
    function ajaxUpdateCategoryRing(){
        var id = '<?php echo $data["id"]?>';
        var title = $("#title").val();
        var picture = $("#picture").val();    
        var position = $("#position").val();    
        
        var strUrl = "<?=$url->createUrl("ringBack/ajaxUpdateCategoryRing") ?>";  
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                id:id,
                title:title,
                picture:picture,    
                position:position,    
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    history.go(-1);
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }          
        });
    }
</script>
<div class="main clearfix">
    <div class="box clearfix bottom30">
        <ul class="form4">
            <li class="clearfix">
                <label><strong>Tên danh mục </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width:360px" value="<?php echo $data["title"]?>" id="title" maxlength="40"> 
                </div>
            </li>
            <li class="clearfix">
                <label><strong>Icon thể loại </strong>:</label>
                <div class="filltext">
                    <p>
                        <input type="hidden" id="txtFileName" readonly="readonly"/>
                        <input type="text" id="urlFile" style="border:1px solid #DFDFDF; width: 200px;">                            
                        <span id="spanButtonPlaceHolder"></span>
                    </p>
                    <br/>
                    <div class="fieldset flash" id="fsUploadProgress">
                        <span class="legend">File upload</span>
                    </div>
                    <input type="hidden" id="picture" value="<?php echo $data["picture"];?>"/>
                    <p id="show_pic">
                        <img src="<?php echo Common::getImage($data["picture"], "ringBack", $data["create_date"]);?>" alt="">
                    </p>
                </div>
            </li>
            <li class="clearfix">
                <label><strong>Tên danh mục </strong>:</label>
                <div class="filltext">
                    <input type="text" style="width:360px" value="<?php echo $data["position"]?>" id="position">  (Thấp lên trên)
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext">
                    <input type="button" id="button_save" value=" Sửa " class="btn-bigblue" onclick="ajaxUpdateCategoryRing();"> 
                    &nbsp;
                    <input onclick="history.go(-1)" type="button" value=" Quay lại " class="btn-bigblue">
                </div>
            </li>
            <li class="clearfix"><label>&nbsp;</label>
                <div class="filltext" style="color: red;" id="show_error"></div>
            </li>
        </ul>
    </div>
</div>